<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class AddressController extends Controller{
    //数据显示
    public function address_table(Request $request){
        $page=$request->get('page');
        $limit=$request->get('limit');
        $crows=DB::table('index_city')->get();
        $rows=Db::table('index_city')->simplePaginate($limit,'*',$limit,$page);
        $data=[
            "code"=>0,
            "msg"=>'',
            "count"=>count($crows),
            "data"=>$rows->items(),
            "limit"=>$limit
        ];
        return json_encode($data);
    }
    //添加服务区
    public function address_insert(Request $request){
        $data=$request->post('result');
        $rows=DB::table('index_city')->insert($data);
        if($rows){
            return 1;
        }
    }
    //修改服务区回显
    public function address_edit($id){
        $rows=DB::table('index_city')->where('id',$id)->first();
        return view('admin.address.address_edit',['rows'=>$rows]);
    }
    //修改服务区
    public function address_update(Request $request){
        $data=$request->post('result');
        $rows=DB::table('index_city')->where('id',$data['id'])->update($data);
        if($rows){
            return 1;
        }
    }
    //删除服务区
    public function address_del(Request $request){
        $id=$request->input('id');
        $rows=DB::table('index_city')->where('id',$id)->delete();
        if($rows){
            return 1;
        }
    }
}